package com.test.java;

import java.text.ParseException;
import java.util.Scanner;

/**
 * 从批量输入中，获取出生年月最年长和最年幼的人，然后输出
 * Date对象返回自1970 年1 月1 日午夜（通用时间）以来的毫秒数
 * =============================================================
 * Version          Author          Date            Description
 * 1.0              白建         2017/12/26             创建
 * =============================================================
 */
public class Java_19
{

    public static void main(String[] args)
            throws ParseException
    {

        Scanner scanner = new Scanner(System.in);
        String maxPerson = "", minPerson = "", temp;
        String today = "2014/09/06";
        String from = "1814/09/06";
        String maxBirth = "2014/09/07";
        String minBirth = "1814/09/05";
        String current;
        String[] strings;
        int count = 0;

        int num = scanner.nextInt();
        scanner.nextLine();

        for (int i = 0; i < num; i++)
        {
            temp = scanner.nextLine();
            strings = temp.split(" ");
            current = strings[1];
            if (validateBirthDate(current, today, from))
            {
                if (current.compareTo(maxBirth) < 0)
                {
                    maxPerson = strings[0];
                    maxBirth = current;
                }
                if (current.compareTo(minBirth) > 0)
                {
                    minPerson = strings[0];
                    minBirth = current;
                }
                count++;
            }
        }
        System.out.println(count + " " + maxPerson + " " + minPerson);
    }

    private static boolean validateBirthDate(String current, String today, String from)
            throws ParseException
    {

        if (today.compareTo(current) >= 0 && current.compareTo(from) >= 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
